package net.muchine.core.support;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import org.springframework.stereotype.Component;

@Component
public class Properties {
	private static final String TIMEZONE_ID_PREFIXES =
		      "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*";

	private List<TimeZone> timeZones = null;
	
   public List<TimeZone> getTimeZones() {
      if (timeZones == null) {
         initTimeZones();
      }
      return timeZones;
   }

   private void initTimeZones() {
      timeZones = new ArrayList<TimeZone>();
      final String[] timeZoneIds = TimeZone.getAvailableIDs();
      
      for (final String id : timeZoneIds) {
         if (id.matches(TIMEZONE_ID_PREFIXES)) {
            timeZones.add(TimeZone.getTimeZone(id));
         }
      }
      Collections.sort(timeZones, new Comparator<TimeZone>() {
         public int compare(final TimeZone a, final TimeZone b) {
        	 return a.getRawOffset() - b.getRawOffset();
//            return String.valueOf(a.getRawOffset()).compareTo(String.valueOf(b.getRawOffset()));
         }
      });
   }
		   
	public List<Map<String, String>> getTimezone() {
		final String[] ids = TimeZone.getAvailableIDs();
		
		final List<TimeZone> timezones = new ArrayList<TimeZone>();
		for (final String id : ids) {
			timezones.add(TimeZone.getTimeZone(id));
		}
		
		return null;
	}
	
	public static void main(String[] args) {
		Properties properties = new Properties();
		
		List<TimeZone> timezones = properties.getTimeZones();
		
		for (TimeZone timezone : timezones) {
//			System.out.println(TimeZone.getTimeZone("Seoul"));
			
			System.out.println(timezone.getID() + ": " + String.valueOf(timezone.getRawOffset()));
			
			if ("Adelaide".matches(timezone.getID().split("/")[1]))
				System.out.println(timezone.getID() + ": " + String.valueOf(timezone.getRawOffset() / 3600000));
						
//			System.out.println(timezone.getDisplayName());
			if ("Seoul".matches(timezone.getID().split("/")[1]))
				System.out.println(timezone.getID() + ": " + String.valueOf(timezone.getRawOffset() / 3600000));
		}
		
		
		
	}
}
